package com.wangzhenyu.learn.test.designPattern

import com.wangzhenyu.common.util.log.LogUtil


//工厂模式


@Suppress("UNUSED")
object CFactoryPattern {


    abstract class Pizza(name: String) {

        protected val name: String

        init {
            this.name = name
        }

        abstract fun prepare()

        fun cut() {
            LogUtil.default01("切割成合适的形状")
        }

    }

    class ApplePizza(name: String) : Pizza(name) {
        override fun prepare() {
            LogUtil.default01("准备了苹果披萨原材料")
        }

    }

    class BananaPizza(name: String) : Pizza(name) {
        override fun prepare() {
            LogUtil.default01("准备了香蕉披萨原材料")
        }
    }

    class WaterMelonPizza(name: String) : Pizza(name) {
        override fun prepare() {
            LogUtil.default01("准备了西瓜披萨原材料")
        }
    }

    class ChickenPizza(name: String) : Pizza(name) {
        override fun prepare() {
            LogUtil.default01("准备了鸡肉披萨原材料")
        }
    }


    class BeefPizza(name: String) : Pizza(name) {
        override fun prepare() {
            LogUtil.default01("准备了牛肉披萨原材料")
        }
    }

    abstract class BaseFactory {
        abstract fun createPizza(type: String): Pizza?
    }


    class FruitFactory : BaseFactory() {
        override fun createPizza(type: String): Pizza? {
            return when (type) {
                "apple" -> ApplePizza("apple")
                "banana" -> BananaPizza("banana")
                "waterMelon" -> WaterMelonPizza("waterMelon")
                else -> null
            }
        }
    }

    class MeetFactory : BaseFactory() {
        override fun createPizza(type: String): Pizza? {
            return when (type) {
                "chicken" -> ChickenPizza("chicken")
                "beef" -> BeefPizza("beef")
                else -> null
            }
        }
    }
}